//
//  NetWorkingUtils.m
//  CNKICommunity
//
//  Created by wei on 17/1/22.
//  Copyright © 2017年 CNKI. All rights reserved.
//

#import "NetWorkingUtils.h"
#import "AFNetworkReachabilityManager.h"

@implementation NetWorkingUtils

+(void)netWorkstate:(netStateBlock)block
{
    AFNetworkReachabilityManager *manager = [AFNetworkReachabilityManager sharedManager];
    //开启网络检测
    [manager startMonitoring];
    //检测结果
    __block typeof(self)weakself = self;
    [manager setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status == 0 || status == 1)
        {
            //弹出提示框
            block(status);
            [weakself showWarningView];
        }
        else
        {
            block(status);
        }
    }];
}
+(void)showWarningView
{
    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"网络断开,请检查您的网络设置" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置",nil];
    [alert show];
    
}
+(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex==0) {
        NSLog(@"取消");
    }else{
        [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }
}

@end
